//
//  RRPresentationController.swift
//  SwiftSina
//
//  Created by Jason Ding on 16/8/17.
//  Copyright © 2016年 Jason Ding. All rights reserved.
//

import UIKit

class RRPresentationController: UIPresentationController {
    
    lazy var coverView = UIView()
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        // 1.设置展示控制器view的尺寸
        presentedView()?.frame = CGRect(x: 100, y: 56, width: 180, height: 250)
        
        // 2.添加蒙版
        setupCoverView()
    }
}

extension RRPresentationController {
    private func setupCoverView(){
        containerView?.insertSubview(coverView, atIndex: 0)
        coverView.backgroundColor = UIColor(white: 0.8,alpha: 0.8)
        coverView.frame = containerView!.bounds;
        
        // 添加手势
        let tap = UITapGestureRecognizer(target: self, action: #selector(RRPresentationController.coverViewCallback))
        coverView.addGestureRecognizer(tap)
        
    }
}

// MARK:- 手势回调
extension RRPresentationController {
    @objc private func coverViewCallback(){
        presentedViewController.dismissViewControllerAnimated(true) { 
            
        }
    }
}